package com.xinya.wanandroidclient.ui.home

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.xinya.wanandroidclient.base.BaseViewModel
import com.xinya.wanandroidclient.bean.HomeArticleBean
import com.xinya.wanandroidclient.bean.HomeBannerBean

/**
 *
 * @ClassName:      HomeViewModel$
 * @Description:    java类作用描述
 * @Author:         xinya
 * @CreateDate:     2021/2/24$ 14:56$
 * @UpdateRemark:   更新内容
 * @Version:        1.0
 */
class HomeViewModel : BaseViewModel() {

    private var currentPage = 0;
    private val repo by lazy { HomeRepo(viewModelScope) }

    val bannerLiveData = MutableLiveData<MutableList<HomeBannerBean>>()
    val articleLiveData = MutableLiveData<HomeArticleBean>()
    val articleTopLiveData = MutableLiveData<MutableList<HomeArticleBean.Data>>()

    fun getHomeBanner() {
        repo.getBanner(bannerLiveData)
    }

    fun getHomeArticle(refresh: Boolean) {
        if (refresh) {
            currentPage = 0
            repo.getArticleTop(articleTopLiveData, refreshStateLiveData)
            return
        }
        repo.getArticle(currentPage++, articleLiveData, refreshStateLiveData)
    }
}